<?php

class PdoAdmin extends PdoConnect {

    public function readAll() {
        try {
            $this->open();
            $sql = "SELECT * FROM `administrateur` ORDER BY PSEUDOADMIN";
            $prep = $this->pdo->prepare($sql);

            $prep->execute();
            $prep->setFetchMode(PDO::FETCH_ASSOC);


            return $prep;
        } catch (PDOException $e) {
            $msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
            die($msg);
        }
    }

    public function readOne($IdAdmin) {
        try {
            $this->open();
            $sql = "SELECT * FROM `administrateur` WHERE IDADMIN=$IdAdmin";
            $prep = $this->pdo->prepare($sql);

            $prep->execute();

            $admin = new Admin();
            $ligne = $prep->fetch(PDO::FETCH_OBJ);
            $admin->setIdAdmin($ligne->IDADMIN);
            $admin->setPseudoAdmin($ligne->PSEUDOADMIN);
            $admin->setNomAdmin($ligne->NOMADMIN);
            $admin->setPrenomAdmin($ligne->PRENOMADMIN);
            $admin->setMotdePasseAdmin($ligne->MOTDEPASSEADMIN);
            $admin->setAdresseelecAdmin($ligne->ADRESSEELECADMIN);

            return $admin;
        } catch (PDOException $e) {
            $msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
            die($msg);
        }
    }



}
